package com.ruoyi.post.service.impl;

import java.time.LocalDate;
import java.util.*;
import java.time.LocalDateTime;

import com.ruoyi.circle.dao.ICircleStatisticsDao;
import com.ruoyi.points.dao.IPointsChangeRecordDao;
import com.ruoyi.post.domain.*;
import com.ruoyi.post.mapper.*;
import com.ruoyi.tag.domain.PostTagsRel;
import com.ruoyi.tag.mapper.PostTagsRelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.ruoyi.post.service.IPostBasicInfoService;
import org.springframework.transaction.annotation.Transactional;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.tms.v20201229.TmsClient;
import com.tencentcloudapi.tms.v20201229.models.TextModerationRequest;
import com.tencentcloudapi.tms.v20201229.models.TextModerationResponse;

/**
 * 帖子管理Service业务层处理
 *
 * @author 区嘉盛
 * @date 2025-06-10
 */
@Service
public class PostBasicInfoServiceImpl implements IPostBasicInfoService {
    @Autowired
    private PostBasicInfoMapper postBasicInfoMapper;

    @Autowired
    private ICircleStatisticsDao circleStatisticsDao;

    @Autowired
    private PostLikeRecordMapper postLikeRecordMapper;

    @Autowired
    private PostCommentInfoMapper postCommentInfoMapper;

    @Autowired
    private PostFavoriteRecordMapper postFavoriteRecordMapper;

    @Autowired
    private PostCommentLikeRecordMapper postCommentLikeRecordMapper;

    @Autowired
    private PostTagsRelMapper postTagsRelMapper;

    @Autowired
    private IPointsChangeRecordDao pointsChangeRecordDao;

    @Value("${spring.tencent.cloud.secretId}")
    private String secretId;

    @Value("${spring.tencent.cloud.secretKey}")
    private String secretKey;

    @Value("${spring.tencent.cloud.region}")
    private String region;

    @Value("${spring.tencent.cloud.tms.bizType}")
    private String bizType;

    /**
     * 查询帖子管理
     *
     * @param id 帖子管理主键
     * @return 帖子管理
     */
    @Override
    public PostBasicInfo selectPostBasicInfoById(Long id) {
        return postBasicInfoMapper.selectPostBasicInfoById(id);
    }

    /**
     * 查询帖子管理列表
     *
     * @param postBasicInfo 帖子管理
     * @return 帖子管理
     */
    @Override
    public List<PostBasicInfo> selectPostBasicInfoList(PostBasicInfo postBasicInfo) {
        return postBasicInfoMapper.selectPostBasicInfoList(postBasicInfo);
    }

    /**
     * 新增帖子管理
     *
     * @param postBasicInfo 帖子管理
     * @return 结果
     */
    @Override
    public int insertPostBasicInfo(PostBasicInfo postBasicInfo) {
        int result = postBasicInfoMapper.insertPostBasicInfo(postBasicInfo);
        if (result > 0 && postBasicInfo.getCircleId() != null &&
                (postBasicInfo.getIsDraft() == null || postBasicInfo.getIsDraft() == 0L)) {
            circleStatisticsDao.updateCirclePostCount(postBasicInfo.getCircleId());
            circleStatisticsDao.updateCircleHeatScore(postBasicInfo.getCircleId());

        }
        return result;
    }

    /**
     * 修改帖子管理
     *
     * @param postBasicInfo 帖子管理
     * @return 结果
     */
    @Override
    public int updatePostBasicInfo(PostBasicInfo postBasicInfo) {
        PostBasicInfo oldPost = postBasicInfoMapper.selectPostBasicInfoById(postBasicInfo.getId());
        int result = postBasicInfoMapper.updatePostBasicInfo(postBasicInfo);
        if (result > 0 && oldPost != null && postBasicInfo.getCircleId() != null) {
            boolean oldIsDraft = oldPost.getIsDraft() != null && oldPost.getIsDraft() == 1L;
            boolean newIsDraft = postBasicInfo.getIsDraft() != null && postBasicInfo.getIsDraft() == 1L;
            if (oldIsDraft != newIsDraft) {
                circleStatisticsDao.updateCirclePostCount(postBasicInfo.getCircleId());
                circleStatisticsDao.updateCircleHeatScore(postBasicInfo.getCircleId());
            }
        }
        return result;
    }

    /**
     * 删除帖子管理信息
     *
     * @param id 帖子管理主键
     * @return 结果
     */
    @Override
    public int deletePostBasicInfoById(Long id) {
        PostBasicInfo post = postBasicInfoMapper.selectPostBasicInfoById(id);
        int result = postBasicInfoMapper.deletePostBasicInfoById(id);
        if (result > 0 && post != null && post.getCircleId() != null &&
                (post.getIsDraft() == null || post.getIsDraft() == 0L)) {
            circleStatisticsDao.updateCirclePostCount(post.getCircleId());
            circleStatisticsDao.updateCircleHeatScore(post.getCircleId());
        }
        return result;
    }

    /**
     * 批量删除帖子管理
     *
     * @param ids 需要删除的帖子管理主键
     * @return 结果
     */
    @Override
    public int deletePostBasicInfoByIds(Long[] ids) {
        Set<Long> affectedCircles = new HashSet<>();
        for (Long id : ids) {
            PostBasicInfo post = postBasicInfoMapper.selectPostBasicInfoById(id);
            if (post != null && post.getCircleId() != null &&
                    (post.getIsDraft() == null || post.getIsDraft() == 0L)) {
                affectedCircles.add(post.getCircleId());
            }
        }
        int result = postBasicInfoMapper.deletePostBasicInfoByIds(ids);
        if (result > 0) {
            for (Long circleId : affectedCircles) {
                circleStatisticsDao.updateCirclePostCount(circleId);
                circleStatisticsDao.updateCircleHeatScore(circleId);
            }
        }
        return result;
    }

    /**
     * 用户发布帖子
     *
     * @param postBasicInfo 帖子信息
     * @param isDraft       是否为草稿
     * @return 结果
     */
    @Override
    @Transactional
    public int publishPost(PostBasicInfo postBasicInfo, boolean isDraft) {
        postBasicInfo.setIsDraft(0L);
        postBasicInfo.setLikeCount(0L);
        postBasicInfo.setCommentCount(0L);
        postBasicInfo.setFavoriteCount(0L);
        int result;
        // 如果id=0，则插入新数据，否则更新草稿数据
        if (postBasicInfo.getId() == 0) {
            result = postBasicInfoMapper.insertPostBasicInfo(postBasicInfo);
        } else {
            result = postBasicInfoMapper.updatePostBasicInfo(postBasicInfo);
        }

        if (result > 0) {
            if (!isDraft && postBasicInfo.getCircleId() != null) {
                circleStatisticsDao.updateCirclePostCount(postBasicInfo.getCircleId());
                circleStatisticsDao.updateCircleHeatScore(postBasicInfo.getCircleId());
            }
            if (!isDraft && postBasicInfo.getAuthorUserId() != null) {
                pointsChangeRecordDao.recordAndUpdatePoints(postBasicInfo.getAuthorUserId(), 1L, 2L, null);
            }
        }
        return result;
    }

    /**
     * 保存帖子草稿
     *
     * @param postBasicInfo 帖子信息
     * @return 结果
     */
    @Override
    public int savePostDraft(PostBasicInfo postBasicInfo) {
        postBasicInfo.setIsDraft(1L);
        postBasicInfo.setLikeCount(0L);
        postBasicInfo.setCommentCount(0L);
        postBasicInfo.setFavoriteCount(0L);
        // 如果已经存在ID，则更新原本的草稿数据，否则插入
        if (postBasicInfo.getId() == 0) {
            return postBasicInfoMapper.insertPostBasicInfo(postBasicInfo);
        } else {
            return postBasicInfoMapper.updatePostBasicInfo(postBasicInfo);
        }
    }

    /**
     * 用户删除自己的帖子
     *
     * @param postId 帖子ID
     * @param userId 用户ID
     * @return 结果
     */
    @Override
    public int deleteUserPost(Long postId, Long userId) {
        PostBasicInfo post = postBasicInfoMapper.selectPostBasicInfoById(postId);
        if (post == null || !post.getAuthorUserId().equals(userId)) {
            return 0;
        }
        int result = postBasicInfoMapper.deletePostBasicInfoById(postId);
        if (result > 0 && post.getCircleId() != null &&
                (post.getIsDraft() == null || post.getIsDraft() == 0L)) {
            circleStatisticsDao.updateCirclePostCount(post.getCircleId());
            circleStatisticsDao.updateCircleHeatScore(post.getCircleId());
        }
        return result;
    }

    /**
     * 根据圈子ID查询帖子列表
     *
     * @param circleId 圈子ID
     * @return 帖子列表
     */
    @Override
    public List<PostBasicInfo> selectPostsByCircleId(Long circleId) {
        PostBasicInfo queryParam = new PostBasicInfo();
        queryParam.setCircleId(circleId);
        queryParam.setIsDraft(0L);
        return postBasicInfoMapper.selectPostBasicInfoList(queryParam);
    }

    /**
     * 查询用户的帖子列表
     *
     * @param userId 用户ID
     * @return 帖子列表
     */
    @Override
    public List<PostBasicInfo> selectPostsByUserId(Long userId) {
        PostBasicInfo queryParam = new PostBasicInfo();
        queryParam.setAuthorUserId(userId);
        return postBasicInfoMapper.selectPostBasicInfoList(queryParam);
    }

    /**
     * 帖子点赞/取消点赞
     *
     * @param postId 帖子ID
     * @param userId 用户ID
     * @return 结果
     */
    @Override
    @Transactional
    public int togglePostLike(Long postId, Long userId) {
        PostLikeRecord existingRecord = postLikeRecordMapper.selectPostLikeRecordByPostAndUser(postId, userId);
        if (existingRecord == null) {
            PostLikeRecord likeRecord = new PostLikeRecord();
            likeRecord.setPostId(postId);
            likeRecord.setUserId(userId);
            likeRecord.setLikeTime(LocalDateTime.now());
            likeRecord.setLikeStatus(1);
            int result = postLikeRecordMapper.insertPostLikeRecord(likeRecord);
            if (result > 0) {
                updatePostLikeCount(postId);
                PostBasicInfo post = postBasicInfoMapper.selectPostBasicInfoById(postId);
                if (post != null && post.getAuthorUserId() != null && !post.getAuthorUserId().equals(userId)) {
                    pointsChangeRecordDao.recordAndUpdatePoints(post.getAuthorUserId(), 1L, 3L, null);
                }
            }
            return result;
        } else {
            int oldStatus = existingRecord.getLikeStatus();
            existingRecord.setLikeStatus(oldStatus == 1 ? 0 : 1);
            existingRecord.setLikeTime(LocalDateTime.now());
            int result = postLikeRecordMapper.updatePostLikeRecord(existingRecord);
            if (result > 0) {
                updatePostLikeCount(postId);
            }
            return result;
        }
    }

    /**
     * 帖子收藏/取消收藏
     *
     * @param postId 帖子ID
     * @param userId 用户ID
     * @return 结果
     */
    @Override
    @Transactional
    public int togglePostFavorite(Long postId, Long userId) {
        PostFavoriteRecord existingRecord = postFavoriteRecordMapper.selectPostFavoriteRecordByPostAndUser(postId, userId);
        if (existingRecord == null) {
            PostFavoriteRecord favoriteRecord = new PostFavoriteRecord();
            favoriteRecord.setPostId(postId);
            favoriteRecord.setUserId(userId);
            favoriteRecord.setFavoriteTime(LocalDateTime.now());
            favoriteRecord.setFavoriteStatus(1);
            int result = postFavoriteRecordMapper.insertPostFavoriteRecord(favoriteRecord);
            if (result > 0) {
                updatePostFavoriteCount(postId);
                PostBasicInfo post = postBasicInfoMapper.selectPostBasicInfoById(postId);
                if (post != null && post.getAuthorUserId() != null && !post.getAuthorUserId().equals(userId)) {
                    pointsChangeRecordDao.recordAndUpdatePoints(post.getAuthorUserId(), 1L, 4L, null);
                }
            }
            return result;
        } else {
            int oldStatus = existingRecord.getFavoriteStatus();
            existingRecord.setFavoriteStatus(oldStatus == 1 ? 0 : 1);
            existingRecord.setFavoriteTime(LocalDateTime.now());
            int result = postFavoriteRecordMapper.updatePostFavoriteRecord(existingRecord);
            if (result > 0) {
                updatePostFavoriteCount(postId);
            }
            return result;
        }
    }

    /**
     * 发表评论
     *
     * @param postCommentInfo 评论信息
     * @param isDraft         是否为草稿
     * @return 结果
     */
    @Override
    @Transactional
    public int addComment(PostCommentInfo postCommentInfo, boolean isDraft) {
        postCommentInfo.setIsDraft(isDraft ? 1L : 0L);
        postCommentInfo.setLikeCount(0L);
        int result = postCommentInfoMapper.insertPostCommentInfo(postCommentInfo);
        if (result > 0) {
            updatePostCommentCount(postCommentInfo.getPostId());
            if (!isDraft && (postCommentInfo.getParentCommentId() == null || postCommentInfo.getParentCommentId() == 0L)) {
                PostBasicInfo post = postBasicInfoMapper.selectPostBasicInfoById(postCommentInfo.getPostId());
                if (post != null && post.getAuthorUserId() != null) {
                    pointsChangeRecordDao.recordAndUpdatePoints(post.getAuthorUserId(), 1L, 5L, null);
                }
            }
        }
        return result;
    }

    /**
     * 查询帖子评论列表
     *
     * @param postId 帖子ID
     * @return 评论列表
     */
    @Override
    public List<PostCommentInfo> selectCommentsByPostId(Long postId) {
        return postCommentInfoMapper.selectCommentsByPostId(postId);
    }

    /**
     * 查询用户收藏的帖子列表
     *
     * @param userId 用户ID
     * @return 收藏的帖子列表
     */
    @Override
    public List<PostBasicInfo> selectFavoritePostsByUserId(Long userId) {
        List<PostFavoriteRecord> favoriteRecords = postFavoriteRecordMapper.selectFavoritesByUserId(userId);
        List<PostBasicInfo> favoritePosts = new ArrayList<>();
        for (PostFavoriteRecord record : favoriteRecords) {
            if (record.getFavoriteStatus() == 1) {
                PostBasicInfo post = postBasicInfoMapper.selectPostBasicInfoById(record.getPostId());
                if (post != null) {
                    favoritePosts.add(post);
                }
            }
        }
        return favoritePosts;
    }

    /**
     * 更新帖子点赞数
     *
     * @param postId 帖子ID
     * @return 帖子点赞数
     */
    private void updatePostLikeCount(Long postId) {
        int likeCount = postLikeRecordMapper.countLikesByPostId(postId);
        PostBasicInfo post = new PostBasicInfo();
        post.setId(postId);
        post.setLikeCount((long) likeCount);
        postBasicInfoMapper.updatePostBasicInfo(post);
    }

    /**
     * 更新帖子收藏数
     *
     * @param postId 帖子ID
     * @return 帖子收藏数
     */
    private void updatePostFavoriteCount(Long postId) {
        int favoriteCount = postFavoriteRecordMapper.countFavoritesByPostId(postId);
        PostBasicInfo post = new PostBasicInfo();
        post.setId(postId);
        post.setFavoriteCount((long) favoriteCount);
        postBasicInfoMapper.updatePostBasicInfo(post);
    }

    /**
     * 更新帖子评论数
     *
     * @param postId 帖子ID
     * @return 帖子评论数
     */
    private void updatePostCommentCount(Long postId) {
        int commentCount = postCommentInfoMapper.countCommentsByPostId(postId);
        PostBasicInfo post = new PostBasicInfo();
        post.setId(postId);
        post.setCommentCount((long) commentCount);
        postBasicInfoMapper.updatePostBasicInfo(post);
    }

    /**
     * 用户删除自己的评论
     *
     * @param commentId 评论ID
     * @param userId    用户ID
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteUserComment(Long commentId, Long userId) {
        PostCommentInfo comment = postCommentInfoMapper.selectPostCommentInfoById(commentId);
        if (comment == null || !comment.getCommenterUserId().equals(userId)) {
            return 0;
        }
        int result = postCommentInfoMapper.deletePostCommentInfoById(commentId);
        if (result > 0) {
            updatePostCommentCount(comment.getPostId());
        }
        return result;
    }

    /**
     * 评论点赞/取消点赞
     *
     * @param commentId 评论ID
     * @param userId    用户ID
     * @return 结果
     */
    @Override
    @Transactional
    public int toggleCommentLike(Long commentId, Long userId) {
        PostCommentLikeRecord existingRecord = postCommentLikeRecordMapper.selectPostCommentLikeRecordByCommentAndUser(commentId, userId);
        if (existingRecord == null) {
            PostCommentLikeRecord likeRecord = new PostCommentLikeRecord();
            likeRecord.setCommentId(commentId);
            likeRecord.setUserId(userId);
            likeRecord.setLikeTime(LocalDateTime.now());
            likeRecord.setLikeStatus(1);
            int result = postCommentLikeRecordMapper.insertPostCommentLikeRecord(likeRecord);
            if (result > 0) {
                updateCommentLikeCount(commentId);
                PostCommentInfo comment = postCommentInfoMapper.selectPostCommentInfoById(commentId);
                if (comment != null && comment.getCommenterUserId() != null && !comment.getCommenterUserId().equals(userId)) {
                    pointsChangeRecordDao.recordAndUpdatePoints(comment.getCommenterUserId(), 1L, 6L, null);
                }
            }
            return result;
        } else {
            int oldStatus = existingRecord.getLikeStatus();
            existingRecord.setLikeStatus(oldStatus == 1 ? 0 : 1);
            existingRecord.setLikeTime(LocalDateTime.now());
            int result = postCommentLikeRecordMapper.updatePostCommentLikeRecord(existingRecord);
            if (result > 0) {
                updateCommentLikeCount(commentId);
            }
            return result;
        }
    }

    /**
     * 更新评论点赞数
     *
     * @param commentId 评论ID
     * @return 评论点赞数
     */
    private void updateCommentLikeCount(Long commentId) {
        int likeCount = postCommentLikeRecordMapper.countLikesByCommentId(commentId);
        PostCommentInfo comment = new PostCommentInfo();
        comment.setId(commentId);
        comment.setLikeCount((long) likeCount);
        postCommentInfoMapper.updatePostCommentInfo(comment);
    }

    /**
     * AI审核帖子内容
     *
     * @param postTitle   帖子标题
     * @param postContent 帖子内容
     * @return 审核结果
     */
    @Override
    public String auditPostContent(String postTitle, String postContent) {
        try {
            String content = "帖子标题：" + (postTitle != null ? postTitle : "") + "\n" +
                    "帖子内容：" + (postContent != null ? postContent : "");
            return auditContentByTencentCloud(content);
        } catch (Exception e) {
            return "PASS";
        }
    }

    /**
     * AI审核评论内容
     *
     * @param commentContent 评论内容
     * @return 审核结果
     */
    @Override
    public String auditCommentContent(String commentContent) {
        try {
            String content = "评论内容：" + (commentContent != null ? commentContent : "");
            return auditContentByTencentCloud(content);
        } catch (Exception e) {
            return "PASS";
        }
    }

    /**
     * 调用腾讯云内容安全服务审核文本
     *
     * @param content 待审核内容
     * @return 审核结果 PASS或REJECT
     */
    private String auditContentByTencentCloud(String content) {
        try {
            Credential cred = new Credential(secretId, secretKey);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("tms.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            TmsClient client = new TmsClient(cred, region, clientProfile);
            TextModerationRequest req = new TextModerationRequest();
            String encodedContent = Base64.getEncoder().encodeToString(content.getBytes("UTF-8"));
            req.setContent(encodedContent);
            req.setBizType(bizType);
            TextModerationResponse resp = client.TextModeration(req);
            String suggestion = resp.getSuggestion();
            if ("Block".equals(suggestion) || "Review".equals(suggestion)) {
                return "REJECT";
            } else {
                return "PASS";
            }
        } catch (TencentCloudSDKException e) {
            e.printStackTrace();
            return "PASS";
        } catch (Exception e) {
            e.printStackTrace();
            return "PASS";
        }
    }

    /**
     * 根据帖子编码获取最新帖子
     *
     * @param postCode 帖子编码
     * @return 帖子信息
     */
    @Override
    public PostBasicInfo getNewPost(String postCode) {
        return postBasicInfoMapper.getNewPost(postCode);
    }

    /**
     * 给用户查询笔记、收藏、点赞的帖子
     *
     * @param type   1:笔记 2:收藏 3:点赞
     * @param userId 用户ID
     * @return 帖子列表
     */
    @Override
    public List<PostBasicInfo> getPostForUser(Long type, Long userId) {
        List<PostBasicInfo> list;
        if (type == 1L) {
            list = postBasicInfoMapper.getNotes(userId);
        } else if (type == 2L) {
            list = postBasicInfoMapper.getFavorite(userId);
        } else {
            list = postBasicInfoMapper.getLikes(userId);
        }
        return list;
    }

    /**
     * 获取用户点赞的帖子ID列表
     *
     * @param userId 用户ID
     * @return 点赞的帖子ID列表
     */
    @Override
    public List<Integer> getUserLikedPostIds(Long userId) {
        return postBasicInfoMapper.getUserLikedPostIds(userId);
    }

    /**
     * 获取用户收藏的帖子ID列表
     *
     * @param userId 用户ID
     * @return 收藏的帖子ID列表
     */
    @Override
    public List<Integer> getUserFavoritePostIds(Long userId) {
        return postBasicInfoMapper.getUserFavoritePostIds(userId);
    }

    /**
     * 根据帖子标题获取帖子
     *
     * @param postTitle 帖子标题
     * @return 帖子信息
     */
    @Override
    public List<PostBasicInfo> getPostByPostTitle(String postTitle) {
        return postBasicInfoMapper.getPostByPostTitle(postTitle);
    }

    @Override
    public PostBasicInfo getPostDraft(Long authorUserId) {
        return postBasicInfoMapper.getPostDraft(authorUserId);
    }

    /**
     * 发布帖子并设置标签关联（事务性操作）
     *
     * @param postBasicInfo 帖子信息
     * @param tagIds        标签ID列表
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int publishPostWithTags(PostBasicInfo postBasicInfo, List<Long> tagIds) {
        try {
            boolean isDraft = false;
            postBasicInfo.setIsDraft(0L);
            postBasicInfo.setLikeCount(0L);
            postBasicInfo.setCommentCount(0L);
            postBasicInfo.setFavoriteCount(0L);
            int result;
            // 如果id=0，则插入新数据，否则更新草稿数据
            if (postBasicInfo.getId() == 0) {
                result = postBasicInfoMapper.insertPostBasicInfo(postBasicInfo);
            } else {
                result = postBasicInfoMapper.updatePostBasicInfo(postBasicInfo);
            }

            if (result <= 0) {
                throw new RuntimeException("帖子发布失败");
            }

            // 2. 设置标签关联
            if (tagIds != null && !tagIds.isEmpty()) {
                List<PostTagsRel> postTagsRelList = new ArrayList<>();
                int tagResult = 0;
                for (Long tagId : tagIds) {
                    PostTagsRel postTagsRel = new PostTagsRel();
                    postTagsRel.setPostId(postBasicInfo.getId());
                    postTagsRel.setTagId(tagId);
                    postTagsRel.setCreatedTime(LocalDate.now());
                    postTagsRelList.add(postTagsRel);
                }

                for (PostTagsRel postTagsRel : postTagsRelList) {
                    tagResult = postTagsRelMapper.insertPostTagsRel(postTagsRel);
                }
                if (tagResult <= 0) {
                    throw new RuntimeException("标签关联设置失败");
                }
            }

            if (result > 0) {
                if (!isDraft && postBasicInfo.getCircleId() != null) {
                    circleStatisticsDao.updateCirclePostCount(postBasicInfo.getCircleId());
                    circleStatisticsDao.updateCircleHeatScore(postBasicInfo.getCircleId());
                }
                if (!isDraft && postBasicInfo.getAuthorUserId() != null) {
                    pointsChangeRecordDao.recordAndUpdatePoints(postBasicInfo.getAuthorUserId(), 1L, 2L, null);
                }
            }
            return result;

        } catch (Exception e) {
            // 事务会自动回滚
            throw new RuntimeException("发布帖子失败：" + e.getMessage(), e);
        }
    }

    @Override
    public List<Long> getUserCommentLikedByPostId(Long postId, Long userId) {
        return postCommentInfoMapper.getUserCommentLikedByPostId(postId, userId);
    }
}


